﻿@using SCMS.Resources
@model SCMS.UI.Models.POStep2Model
@{AjaxOptions ajaxOpts = new AjaxOptions
{
    UpdateTargetId = "PODiv",
    LoadingElementId = "loading",
    HttpMethod = "Post",
    Url = Url.Action("LoadOtherPODetails")

};}
<div class="partialViewCard">
    <div class="partialViewCardHeader"><h3>@Resources_frank.PurchaseOrder_LoadSingleQ_NewPO:: &nbsp;@ViewBag.PORefNumber&nbsp; (@Resources_frank.PurchaseOrder_String_SingleQuote)</h3></div>
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        <br />
        <h4 style="text-align: center;">@Resources_frank.PurchaseOrder_String_PurchaseOrderItems</h4>
        <center>
            @Ajax.ActionLink(Resources_frank.OrderRequest_AddNewItem4OR_AddNewItem, "Index", new { id = "LoadAddItems" }, new AjaxOptions
       {
           UpdateTargetId = "popup-page",
           LoadingElementId = "popup-loading",
           Url = Url.Action("LoadAddItems/" + Model.EntityPO.Id),
           OnBegin = string.Format("ShowDialogue('{0}')", Resources_frank.ProcurementPlan_CreatePPStep2_AddItemToPP),
           OnSuccess = "clearPOItemNumbers();CenterPopup()"
       })
        </center>
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
            <tr class="grideven">
                <th>
                    @Resources_frank.Global_String_ORRefNo
                </th>
                <th>
                    @Resources_morgan.Global_String_ItemName
                </th>
                <th>
                    @Resources_frank.Budget_CategoryList_Description
                </th>
                <th>
                    @Resources_morgan.Global_String_Quantity
                </th>
                <th>
                    @Resources_frank.PurchaseOrder_AddPOItems_UnitPrice
                </th>
                <th>
                    @Resources_frank.PurchaseOrder_AddPOItems_TotalPrice
                </th>
                <th>
                    @Resources_frank.Budget_CreateSubLine_LineNumber
                </th>
                <th>
                    @Resources_morgan.Global_String_Remarks
                </th>
                <th>
                    @Resources_frank.Global_String_Manage
                </th>
            </tr>
            @for (int i = 0; i < Model.POrderORs.Count; i++)
            {
                <tr class="gridodd">
                    <td rowspan="@Model.POrderORs[i].POItems.Count" title="@Model.POrderORs[i].EntitiyOR.ProjectDonor.ProjectNumber" >
                        @Model.POrderORs[i].EntitiyOR.RefNumber
                    </td>
                    <td>
                        @Model.POrderORs[i].POItems[0].ItemName
                    </td>
                    <td>
                        @Model.POrderORs[i].POItems[0].EntityPOItem.OrderRequestItem.ItemDescription
                    </td>
                    <td align="center">
                        @Model.POrderORs[i].POItems[0].Quantity.ToString("#,##0")
                    </td>
                    <td align="right">
                        @Model.POrderORs[i].POItems[0].UnitCost.ToString("#,##0.00")
                    </td>                
                    <td align="right">
                        @Model.POrderORs[i].POItems[0].TotalCost.ToString("#,##0.00")
                    </td>
                    <td title="@Model.POrderORs[i].POItems[0].EntityPOItem.ProjectBudget.Description" align="center">
                        @Model.POrderORs[i].POItems[0].EntityPOItem.ProjectBudget.LineNumber
                    </td>
                    <td>
                        @Model.POrderORs[i].POItems[0].EntityPOItem.Remarks
                    </td>
                    <td align="center">
                        @Ajax.ActionLink(Resources_frank.Global_String_Edit, "Index", new { id = "EditPOItem" }, new AjaxOptions
                        {
                            UpdateTargetId = "popup-page",
                            LoadingElementId = "popup-loading",
                            Url = Url.Action("EditPOItem/" + Model.POrderORs[i].POItems[0].POItemId),
                            OnBegin = string.Format("ShowDialogue('{0}')", Resources_frank.PurchaseOrder_String_EditPOItem),
                            OnSuccess = "clearPOItemNumbers"
                        })
                            | 
                        @Ajax.ActionLink(Resources_frank.Global_String_Remove, "Index", new { id = "DeletePOItem" }, new AjaxOptions
                        {
                            UpdateTargetId = "PODiv",
                            LoadingElementId = "loading",
                            Confirm = Resources_frank.PurchaseOrder_String_ConfirmRemoveItem,
                            Url = Url.Action("DeletePOItem/" + Model.POrderORs[i].POItems[0].POItemId)
                        })
                    </td>
                </tr>
                   for (int j = 1; j < Model.POrderORs[i].POItems.Count; j++)
                   { 
                    <tr class="gridodd">
                        <td>
                            @Model.POrderORs[i].POItems[j].ItemName
                        </td>
                        <td>
                            @Model.POrderORs[i].POItems[j].EntityPOItem.OrderRequestItem.ItemDescription
                        </td>
                        <td align="right">
                            @Model.POrderORs[i].POItems[j].Quantity.ToString("#,##0")
                        </td>
                        <td align="right">
                            @Model.POrderORs[i].POItems[j].UnitCost.ToString("#,##0.00")
                        </td>                
                        <td align="right">
                            @Model.POrderORs[i].POItems[j].TotalCost.ToString("#,##0.00")
                        </td>
                        <td title="@Model.POrderORs[i].POItems[j].EntityPOItem.ProjectBudget.Description" align="center">
                            @Model.POrderORs[i].POItems[j].EntityPOItem.ProjectBudget.LineNumber
                        </td>
                        <td>
                            @Model.POrderORs[i].POItems[0].EntityPOItem.Remarks
                        </td>
                        <td align="center">
                            @Ajax.ActionLink(Resources_frank.Global_String_Edit, "Index", new { id = "EditPOItem" }, new AjaxOptions
                       {
                           UpdateTargetId = "popup-page",
                           LoadingElementId = "popup-loading",
                           Url = Url.Action("EditPOItem/" + Model.POrderORs[i].POItems[j].POItemId),
                           OnBegin = string.Format("ShowDialogue('{0}')", Resources_frank.PurchaseOrder_String_EditPOItem),
                           OnSuccess = "cleanTANumbers"
                       })
                                | 
                            @Ajax.ActionLink(Resources_frank.Global_String_Remove, "Index", new { id = "DeleteItem" }, new AjaxOptions
                       {
                           UpdateTargetId = "PODiv",
                           LoadingElementId = "loading",
                           Confirm = Resources_frank.PurchaseOrder_String_ConfirmRemoveItem,
                           Url = Url.Action("DeletePOItem/" + Model.POrderORs[i].POItems[j].POItemId)
                       })
                        </td>
                    </tr>
                   }
                   if (i + 1 < Model.POrderORs.Count)
                   {
                    <tr>
                        <td colspan="9">&nbsp;</td>
                    </tr>
                   }
            }
        </table>
        <input type="hidden" id="currencyId" value="@Model.EntityPO.CurrencyId" />
        <table width="98%" align="center">
            @if (Model.POrderORs.Count > 0)
            {
                <tr>
                    <td width="50%">
                        @Ajax.ActionLink("<<" + Resources_frank.Global_String_Back, "Index", new { id = "EditSingleQ" }, new AjaxOptions
                   {
                       UpdateTargetId = "PODiv",
                       LoadingElementId = "loading",
                       Url = Url.Action("EditSingleQ/" + Model.EntityPO.Id)
                   })
                    </td>
                    <td align="right" width="50%">
                        @Html.HiddenFor(p => p.EntityPO.Id)
                        <input type="submit" class="btn green" value="@Resources_frank.Global_String_Proceed" />
                    </td>
                </tr>
            }
            else
            {
                <tr>
                    <td width="100%">
                        @Ajax.ActionLink("<<" + Resources_frank.Global_String_Back, "Index", new { id = "LoadSingleQ" }, new AjaxOptions
                   {
                       UpdateTargetId = "PODiv",
                       LoadingElementId = "loading",
                       Url = Url.Action("EditSingleQ/" + Model.EntityPO.Id)
                   })
                    </td>
                </tr>
            }
        </table>    
    }
</div>
